# -*- coding:utf-8 -*-

# author: firstoneyuan
# email: devops_yj@163.com

"""
# 1. 给一个半径，求圆的面积和周长. 圆周率3.14
# 2. 输入两个数，比较大小后，从小到大升序打印.
# 3. 使用三元表达式
# 4. 获取最大值
# 5. 输入n个数，求每次输入后的算数平均数
# 6. 九九乘法表
# 7. 打印九九乘法表方阵的上半部分
# 8. 打印菱形
# 9. 打印对顶三角形
# 10. 打印闪电
# 11. 斐波那契数列，100以内
# 12. 求斐波那契数列数列第101项
# 13. 求10万内的所有素数
# 14. 猴子吃桃问题
"""

"""
# 1. 给一个半径，求圆的面积和周长. 圆周率3.14
r = int(input('r='))
print('area='+str(3.14*r*r))
print('circumference='+str(2*3.14*r))

# 2. 输入两个数，比较大小后，从小到大升序打印.
a = input('first:')
b = input('second:')
if a > b:
    print(b,a)
else:
    print(a,b)

# 3. 使用三元表达式
'''
三目运算符
python没有三目运算符，但提供了三元表达式.
真值  if  条件 else 假值
'''
a = input('first:')
b = input('second:')
print(b,a) if a > b else print(a,b)
"""


# 4. 获取最大值
# 请输入若干个整数，打印出最大值.
"""
m = int(input('Input first number >>>'))
while True:
    c = input('Input a number,not input and exit >>>')
    if c:
        n = int(c)
        if n > m:
            m = n
        print('Max is',m)
        # if m == 'q' and c == 'q':
            # break
    else:
        break


# 5. 输入n个数，求每次输入后的算数平均数
n = 0  # 次数
sum = 0 # 和
while True:
    i = input('>>>')
    if i == 'q':
        break
    n += 1
    sum += int(i)
    avg = sum/n
    print(avg)
"""


# 6. 九九乘法表
# help(print)
"""
for i in range(1,10):
    for j in range(1,i+1):
        print(str(j)+'*'+str(i)+"="+str(i*j),end=' ')
    print()

for i in range(1,10):
    for j in range(1,i+1):
        product = i*j 
        if j>1 and product<10:
            product = str(product) + ' '
        else:
            product = str(product)
        print(str(j) + '*' + str(i) + "=" + product,end=' ')
    print()

for i in range(1,10):
    for j in range(1,i+1):
        print(str(j) + 'x' + str(i) + '=' + str(i * j) + '\t',end=' ')  #\t制表符
    print()

for i in range(1,10):
    line = ''
    for j in range(1,i+1):
        line += '{0}*{1}={2}\t'.format(j,i,i*j)
    print(line)

for i in range(1,10):
    line = ''
    for j in range(1,i+1):
        line += '{0}*{1}={2:<2}\t'.format(j,i,i*j)
    print(line)

for i in range(1,10):
    line = ''
    for j in range(1,i+1):
        line += '{}*{}={:<2}\t'.format(j,i,i*j)
    print(line)
# {2:<2}对应i*j, :<2冒号是分割符号, <表示左对齐,2表示宽度.
"""

# 7. 打印九九乘法表方阵的上半部分
"""
for i in range(1,10):
    print(' '*7*(i-1),end='')
    for j in range(i,10):
        product = i*j 
        if product < 10:
            end = '  '
        else:
            end = ' '
        print(str(i) + '*' + str(j) + "=" +str(i*j),end=end)
    print()

# 8. 打印菱形
for i in range(-3,4):
    if i < 0:
        prespace = -i 
    else:
        prespace = i
    print(' '*prespace + '*'*(7-prespace*2))


print('===='*5)

# 9. 打印对顶三角形
n = 7
e = n//2

for i in range(-e,n-e):
    prespace = -i if i<0 else i 
    print(' '*(e-prespace) + '*'*(2*prespace+1))

print('===='*10)


# 10. 打印闪电
for i in range(-3,4):
    if i<0:
        print(' '*(-i) + '*'*(4+i))
    elif i>0:
        print(' '*3 + '*'*(4-i))
    else:
        print('*'*7)
"""


# 11. 斐波那契数列，100以内
"""
'''
斐波那契数列： 1,1,2,3,5,8,13,21,34,55,89，
如何设F(n)为该数列的第n项(n=N*),这句话可以写成如下形式: F(n)=F(n-1)+F(n-2)  F(0)=0,F(1)=1,F(n)=F(n-1)+F(n-2)
'''  
# 这是一个线性递推数列
print(0)
print(1)
a = 0
b = 1
while True:
    c = a + b 
    if c > 100: break
    a = b
    b = c  
    print(c)


# 12. 求斐波那契数列数列第101项
a = 1
b = 1
index = 2
print('{0},{1}'.format(0,0))
print('{0}，{1}'.format(1,1))
print('{0},{1}'.format(2,1))

while True:
    c = a + b 
    a = b 
    b = c  
    index += 1
    print('{0},{1}'.format(index,c))
    if index == 101:
        break
"""


# 13. 求10万内的所有素数
"""
# 注意效率问题：
for x in range(2,100):
    for i in range(2,x):
        if x % i == 0:
            break
    else:
        print(x)

for x in range(2,100000):
    for i in range(2,int(x ** 0.5)+1):
        if x % i == 0:
            break
    else:
        print(x)


for x in range(3,100000,2):
    for i in range(3,int(x ** 0.5) + 1,2):
        if x % i == 0:
            break
    else:
        print(x)


# 如何计算时间，import datetime

count = 0
for x in range(2,100000):
    for i in range(2,x):
        if x % i == 0:
            break
    else:
        count += 1

print(count)
# 9592



count = 0
for x in range(2,100000):
    for i in range(2,int(x ** 0.5)+1):
        if x % i == 0:
            break
    else:
        count += 1
print(count)

# 应用在密码学领域，都要使用大素数.
"""


# 两种算法的对比的完整代码:
"""
import datetime

upper_limit = 100000
delta = [0,0]
counts = [0,0]

start = datetime.datetime.now()
for _ in range(10):
    counts[0] = 0
    for x in range(2,upper_limit):
        for i in range(2,int(x ** 0.5)+1):
            if x % i == 0:
                break
        else:
            # print(x)
            counts[0] += 1

delta[0] = (datetime.datetime.now() - start).total_seconds()

start = datetime.datetime.now()
for _ in range(10):
    counts[1] = 1
    # print(2)
    for x in range(3,upper_limit,2):
        for i in range(3,int(x ** 0.5)+1,2):
            if x % i == 0:
                break
        else:
            # print(x)
            counts[1] += 1

delta[1] = (datetime.datetime.now() - start).total_seconds()
print(delta,sep="\t")
print(counts,sep="\t")
"""


# 14. 猴子吃桃问题.
'''
猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个.第二天早上又将剩下的桃子吃掉一半，又多吃了一个. 以后每天早上都吃了前一天剩下的一半零一个. 到第10天早上想吃时,只剩下一个桃子了.求第一天共摘多少个桃子.'''

peach = 1
for i in range(9):
    peach = 2*(peach+1)
print(peach)  #1534

